<template>
  <div v-loading="loading">
    <div class="header-search cad-box">
      <!-- <el-input
        v-model="searchValue.realName"
        style="width: 20%"
        clearable
        placeholder="请输入机构名称"
      /> -->
      <el-select
        v-model="searchValue.warningTypeId"
        placeholder="请选择类型"
        style="width: 20%; margin: 0px 10px"
      >
        <el-option
          v-for="item in options1"
          :key="item.dictValue"
          :label="item.dictLabel"
          :value="item.dictValue"
        />
      </el-select>
      <el-select
        v-model="searchValue.urgency"
        placeholder="请选择紧急程度"
        style="width: 20%"
      >
        <el-option
          v-for="item in options2"
          :key="item.dictValue"
          :label="item.dictLabel"
          :value="item.dictValue"
        />
      </el-select>
      <el-select
        v-model="searchValue.handleStatus"
        placeholder="请选择状态"
        style="width: 20%; margin: 0px 10px"
      >
        <el-option
          v-for="item in options3"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-button type="primary" @click="handleEmergencyList">搜 索</el-button>
    </div>

    <div class="content-table cad-box">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="序号" type="index" align="center" />
        <el-table-column prop="areaName" label="机构名称" align="center" />
        <el-table-column prop="date" label="异常类型" align="center">
          <template slot-scope="scope">
            {{
              scope.row.warningTypeId
                ? options1.find(
                  (item) => item.dictValue === scope.row.warningTypeId
                ).dictLabel
                : "-"
            }}
          </template>
        </el-table-column>
        <el-table-column prop="description" label="事件描述" align="center" />
        <el-table-column prop="urgency" label="紧急程度" align="center">
          <template slot-scope="scope">
            {{
              options2.find(
                (item) => item.dictValue === String(scope.row.urgency)
              ).dictLabel
            }}
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="scope">
            {{
              options3.find((item) => item.value === scope.row.handleStatus)
                .label
            }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center" />
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleGoInfo(scope.row.id)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align: right">
        <el-pagination
          :current-page="pagination.pageNum"
          :page-sizes="[10, 15, 30, 50]"
          :page-size="pagination.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { emergencyListArray, emergencyList } from './api'
export default {
  data () {
    return {
      options1: [],
      options2: [],
      options3: [
        {
          value: 0,
          label: '已处理'
        },
        {
          value: 1,
          label: '未处理'
        }
      ],
      value1: '',
      value2: '',
      value3: '',
      loading: false,
      searchValue: {
        realName: '',
        status: '',
        handleStatus: '',
        urgency: '',
        warningTypeId: ''
      },
      tableData: [],
      pagination: {
        pageNum: 0,
        pageSize: 10
      },
      total: 0
    }
  },
  computed: {
    ...mapGetters(['curArea', 'user'])
  },
  async created () {
    await this.handleEmergencyListType()
    await this.handleEmergencyListType1()
    this.handleEmergencyList()
  },
  mounted () {},
  methods: {
    async handleEmergencyListType () {
      const res = await emergencyList('early_warning_type')
      console.log(res, 'handleEmergencyList')
      this.options1 = res
    },
    async handleEmergencyListType1 () {
      const res = await emergencyList('emergency')
      console.log(res, 'handleEmergencyList')
      this.options2 = res
    },
    async handleEmergencyList () {
      const res = await emergencyListArray({
        areaId: this.curArea.id,
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        handleStatus: this.searchValue.handleStatus,
        warningTypeId: this.searchValue.warningTypeId,
        urgency: this.searchValue.urgency
      })
      this.tableData = res.records
      this.total = Number(res.total)
    },
    handleGoInfo (id) {
      this.$router.push(`/government/emergencyDetail?id=${id}`)
    },
    onSubmit () {},
    getTableList () {},
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.pagination.pageSize = val
      this.getTableList()
    },

    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.pagination.pageNum = val
      this.getTableList()
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-drawer__header {
  color: #000 !important;
  font-size: 18px !important;
}

.header-search {
  display: flex;
  margin-bottom: 30px;

  .select-box {
    width: 20%;
    margin: 0 20px;
  }
}

.drawer_box {
  width: 100%;
  padding: 0px 50px;
  .drawer_item {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
    padding: 10px;
  }
}
</style>
